package com.example.tlias.controller;

import com.example.tlias.pojo.Dept;
import com.example.tlias.pojo.Result;

import com.example.tlias.service.DeptServiceI;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("depts")
public class DeptController {

    public static Logger log = LoggerFactory.getLogger(DeptController.class);

    @Autowired
    private DeptServiceI deptService;

//    @RequestMapping(value = "/depts",method = RequestMethod.GET)
    @GetMapping()
    public Result list() {
        log.info("查询全部的部门数据");
        List<Dept> deptList = deptService.list();
        return  Result.success(deptList);
    }

    @GetMapping("/{id}")
    public Result select(@PathVariable Integer id) {
        log.info("select ====== {}", id);
        Dept dept = deptService.select(id);
        return Result.success(dept);
    }

    @DeleteMapping("/{id}")
    public Result delete(@PathVariable Integer id) {
        log.info("delete{}", id);
        deptService.deleteid(id);
        return Result.success();
    }

    @PostMapping
    public Result add(@RequestBody Dept dept) {
        log.info("add{}", dept);
        deptService.add(dept);
        return Result.success();
    }

    @PutMapping()
    public Result update(@RequestBody Dept dept) {
        log.info("update{}", dept);
        deptService.update(dept);
        return Result.success();
    }
}
